
<%@ page import="org.gtesoreria.Afiliado" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'afiliado.label', default: 'Afiliado')}" />
        <title><g:message code="default.show.label" args="[entityName]" /></title>
    </head>
    <body>
        <div class="nav" style="display:none">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
            <span class="menuButton"> <g:link class="afiliados" action="home" controller="afiliado">Afiliados</g:link></span>
            <span class="menuButton"><g:link class="afiliadoBoton" controller="afiliado" action="show" id="${afiliadoInstance?.id}">${afiliadoInstance?.apellidoNombre}</g:link></span>
        </div>
        <div class="body">
            <h1>Adelantos de ${fieldValue(bean: afiliadoInstance, field: 'apellidoNombre')}</h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <div class="list">
            	<table>
                    <thead>
                        <tr>
                        	<g:sortableColumn property="id" title="${message(code: 'adelanto.id.label', default: 'Id')}" />
                        	
                            <g:sortableColumn property="montoTotal" title="${message(code: 'adelanto.monto.label', default: 'Monto')}" />
                        
                            <g:sortableColumn property="fechaOtorgamiento" title="${message(code: 'adelanto.fechaOtorgamiento.label', default: 'Fecha de Otorgamiento')}" />
                        
                            <g:sortableColumn property="fechaPedido" title="${message(code: 'adelanto.fechaPago.label', default: 'Fecha de Solicitud')}" />
                        
                        	<g:sortableColumn property="estado" title="${message(code: 'adelanto.entrego.label', default: 'Estado')}" />
                        	
                            <g:sortableColumn property="entrego" title="${message(code: 'adelanto.entrego.label', default: 'Entrega')}" />
                            
                            <g:sortableColumn property="observaciones" title="${message(code: 'adelanto.observaciones.label', default: 'Observaciones')}" />
                            <th>Mover a:</th>
                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${adelantos}" status="i" var="adelantoInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                        	<td><g:link action="show" id="${adelantoInstance.id}">${fieldValue(bean: adelantoInstance, field: "id")}</g:link></td>
                        
                            <td style="text-align:right"><g:formatNumber number="${adelantoInstance?.montoTotal}" type="number" minFractionDigits="2" maxFractionDigits ="2" roundingMode="HALF_UP" /></td>
                        
                            <td><g:formatDate date="${adelantoInstance?.fechaOtorgamiento}" format="dd-MM-yyyy"></g:formatDate></td>
                            
                            <td><g:formatDate date="${adelantoInstance?.fechaPedido}" format="dd-MM-yyyy"></g:formatDate></td>
                            
                            <td>${fieldValue(bean: adelantoInstance, field: "estado")}</td>
                            
                            <td>${fieldValue(bean: adelantoInstance, field: "entrego")}</td>
                            
                            <td>${fieldValue(bean: adelantoInstance, field: "observaciones")}</td>
                            <td style="padding:1px">
		                            <g:if test="${adelantoInstance?.montoTotal > 0 }">
								        <g:form method="post" action="refinanciarPendiente">
								        <g:hiddenField name="afiliadoId" value="${adelantoInstance?.afiliado?.id }"/>
								        <input type="submit"   class="myButton" name="${ "descuento_" + adelantoInstance?.id}" value="${message(code: 'default.button.buscar.label', default: 'Desc.')}"/>
								        <input type="submit"   class="myButton" name="${ "prestamo_" + adelantoInstance?.id}" value="${message(code: 'default.button.buscar.label', default: 'Prest')}"/>
								        </g:form>
								    </g:if>
							</td>
                    	</tr>
                    </g:each>
                    </tbody>
                </table>
                
            </div>
            <div class="buttons">
                <g:form>
                    <g:hiddenField name="id" value="${afiliadoInstance?.id}" />
                    <span class="button"><g:actionSubmit class="create" action="create" value="${message(code: 'default.button.guardar.label', default: 'Crear adelanto')}" /></span>
                    <span class="button"><g:actionSubmit class="cancel" action="cancel" controller="afiliado" value="${message(code: 'default.button.cancel.label', default: 'Cancelar')}"/></span>
                </g:form>
            </div>
        </div>
    </body>
</html>
